package com.qiyi.player.wonder.plugins.feedback.view.parts.copyrightlimited
{
   import flash.display.Sprite;
   import feedback.OverseaUI;
   import flash.text.TextField;
   import com.qiyi.player.wonder.plugins.feedback.FeedbackDef;
   import flash.events.MouseEvent;
   import flash.net.navigateToURL;
   import flash.net.URLRequest;
   import flash.text.TextFormat;
   import com.qiyi.player.wonder.common.ui.FastCreator;
   import gs.TweenLite;
   import gs.easing.Back;
   
   public class CopyrightLimited extends Sprite
   {
      
      public function CopyrightLimited() {
         super();
         this._overseaUI = new OverseaUI();
         this._titleTF = FastCreator.createLabel(TEXT_TITLE,16777215,18);
         this._titleTF.x = (this._overseaUI.width - this._titleTF.width) / 2;
         this._overseaUI.addChild(this._titleTF);
         this._linkTF = FastCreator.createLabel(TEXT_LINK,16777215);
         this._linkTF.x = (this._overseaUI.width - this._linkTF.width) / 2;
         this._linkTF.y = 52;
         this._overseaUI.addChild(this._linkTF);
         this._englistTF = FastCreator.createLabel(TEXT_ENGLISH,16777215,15);
         this._englistTF.x = (this._overseaUI.width - this._englistTF.width) / 2;
         this._englistTF.y = 80;
         this._overseaUI.addChild(this._englistTF);
         this._preBtn = new TriangleBtn(32,TriangleBtn.FACE_LEFT);
         this._nextBtn = new TriangleBtn(32,TriangleBtn.FACE_RIGHT);
         this._leftText = FastCreator.createLabel("这些也精彩",10066329,16,"",true);
         this._rightText = FastCreator.createLabel("更多",8562957,16,"",true);
         this._rightTextLink = new Sprite();
         this._rightTextLink.addChild(this._rightText);
         this._rightTextLink.mouseChildren = false;
         this._rightTextLink.buttonMode = true;
         this._rightTextLink.addEventListener(MouseEvent.CLICK,this.onMoreClick);
         this._rightTextLink.addEventListener(MouseEvent.ROLL_OVER,this.onRollOver);
         this._rightTextLink.addEventListener(MouseEvent.ROLL_OUT,this.onRollOut);
         this._preBtn.addEventListener(MouseEvent.CLICK,this.onPreBtnClick);
         this._nextBtn.addEventListener(MouseEvent.CLICK,this.onNextBtnClick);
         this._maskMC = new Sprite();
         this._loadInContainer = new Sprite();
         this.getVideoData();
         this.initUI();
      }
      
      private static const TEXT_TITLE:String = "由于版权原因，此视频暂不支持播放";
      
      private static const TEXT_LINK:String = "如果您有其他问题，<a href=\'event:onTextEventClick\'><u>请告知我们</u></a> 我们将尽快查找原因。";
      
      private static const TEXT_ENGLISH:String = "Sorry, this video is not available in your region \n               " + "due to copyright limitations.";
      
      public var _thisW:int = 596;
      
      public var _thisH:int = 198;
      
      private var _overseaUI:OverseaUI;
      
      private var _titleTF:TextField;
      
      private var _linkTF:TextField;
      
      private var _englistTF:TextField;
      
      private var _preBtn:TriangleBtn;
      
      private var _nextBtn:TriangleBtn;
      
      private var _leftText:TextField;
      
      private var _rightText:TextField;
      
      private var _rightTextLink:Sprite;
      
      private var _videoItemArray:Array = null;
      
      private var _maskMC:Sprite = null;
      
      private var _loadInContainer:Sprite = null;
      
      public function get linkTextField() : TextField {
         return this._linkTF;
      }
      
      public function onResize(param1:int, param2:int) : void {
         x = (param1 - this._overseaUI.width) / 2;
         y = (param2 - height) / 2;
      }
      
      private function getVideoData() : void {
         var _loc1_:int = FeedbackDef.OPEN_VIDEOS.item.length();
         this._videoItemArray = new Array();
         var _loc2_:* = 0;
         while(_loc2_ < _loc1_)
         {
            this._videoItemArray[_loc2_] = new OpenVideoItem(FeedbackDef.OPEN_VIDEOS.item[_loc2_].@video_url,FeedbackDef.OPEN_VIDEOS.item[_loc2_].@pic_url,FeedbackDef.OPEN_VIDEOS.item[_loc2_].@title);
            this._videoItemArray[_loc2_].x = _loc2_ * (this._thisW - 86) / 4;
            this._videoItemArray[_loc2_].y = 0;
            this._loadInContainer.addChild(this._videoItemArray[_loc2_]);
            _loc2_++;
         }
      }
      
      private function initUI() : void {
         this._leftText.y = this._overseaUI.y + this._overseaUI.height + 20;
         this._rightTextLink.y = this._leftText.y;
         this._loadInContainer.x = this._overseaUI.x;
         this._loadInContainer.y = this._leftText.y + this._leftText.height;
         this._maskMC.x = this._loadInContainer.x;
         this._maskMC.y = this._loadInContainer.y;
         this._maskMC.graphics.beginFill(16711680);
         this._maskMC.graphics.drawRect(0,0,504,this._thisH);
         this._maskMC.graphics.endFill();
         this._loadInContainer.mask = this._maskMC;
         this._leftText.x = this._loadInContainer.x;
         this._rightTextLink.x = this._loadInContainer.x + this._overseaUI.width - this._rightTextLink.width + 15;
         this._preBtn.x = this._loadInContainer.x - this._preBtn.width - 10;
         this._preBtn.y = this._loadInContainer.y + (124 - this._preBtn.height) / 2;
         this._nextBtn.x = this._loadInContainer.x + this._overseaUI.width + 30;
         this._nextBtn.y = this._preBtn.y;
         addChild(this._loadInContainer);
         addChild(this._overseaUI);
         addChild(this._leftText);
         addChild(this._rightTextLink);
         addChild(this._maskMC);
         addChild(this._preBtn);
         addChild(this._nextBtn);
      }
      
      private function onMoreClick(param1:MouseEvent) : void {
         navigateToURL(new URLRequest(FeedbackDef.OPEN_VIDEOS_LIST_URL),"_blank");
      }
      
      private function onRollOver(param1:MouseEvent) : void {
         this._rightText.setTextFormat(new TextFormat(FastCreator.FONT_MSYH,16,10066329,true,null,true));
      }
      
      private function onRollOut(param1:MouseEvent) : void {
         this._rightText.setTextFormat(new TextFormat(FastCreator.FONT_MSYH,16,8562957,true,null,true));
      }
      
      private function onPreBtnClick(param1:MouseEvent) : void {
         var _loc2_:* = 0;
         var _loc3_:Object = null;
         if(!this._videoItemArray)
         {
            return;
         }
         if(this._videoItemArray.length > 4)
         {
            _loc2_ = 0;
            while(_loc2_ < 4)
            {
               _loc3_ = this._videoItemArray.pop();
               _loc3_.x = this._videoItemArray[0].x - (this._thisW - 86) / 4;
               this._videoItemArray.unshift(_loc3_);
               _loc2_++;
            }
            TweenLite.to(this._loadInContainer,1,
               {
                  "x":this._loadInContainer.x + (this._thisW - 86) / 1,
                  "onComplete":this.enableBtns,
                  "ease":Back.easeOut
               });
            this.disableBtns();
         }
      }
      
      private function onNextBtnClick(param1:MouseEvent) : void {
         var _loc2_:* = 0;
         var _loc3_:Object = null;
         if(!this._videoItemArray)
         {
            return;
         }
         if(this._videoItemArray.length > 4)
         {
            _loc2_ = 0;
            while(_loc2_ < 4)
            {
               _loc3_ = this._videoItemArray.shift();
               _loc3_.x = this._videoItemArray[this._videoItemArray.length - 1].x + (this._thisW - 86) / 4;
               this._videoItemArray.push(_loc3_);
               _loc2_++;
            }
            TweenLite.to(this._loadInContainer,1,
               {
                  "x":this._loadInContainer.x - (this._thisW - 86) / 1,
                  "onComplete":this.enableBtns,
                  "ease":Back.easeOut
               });
            this.disableBtns();
         }
      }
      
      private function enableBtns() : void {
         this._preBtn.addEventListener(MouseEvent.CLICK,this.onPreBtnClick);
         this._nextBtn.addEventListener(MouseEvent.CLICK,this.onNextBtnClick);
         this._preBtn.enable = true;
         this._nextBtn.enable = true;
      }
      
      private function disableBtns() : void {
         this._preBtn.removeEventListener(MouseEvent.CLICK,this.onPreBtnClick);
         this._nextBtn.removeEventListener(MouseEvent.CLICK,this.onNextBtnClick);
         this._preBtn.enable = false;
         this._nextBtn.enable = false;
      }
   }
}
